﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ArticleManagementSystem
{
    public partial class RegistrationInterface : Form
    {
        public RegistrationInterface()
        {
            InitializeComponent();
        }
        SqlConnection con;

        private void button1_Click(object sender, EventArgs e)
        {
            var uid = textBox1.Text;
            var pwd = textBox2.Text;
            var determinepwd = textBox3.Text;
            if (uid == "")
            {
                MessageBox.Show("账号不能为空");
            }
            else if(pwd == "")
            {
                MessageBox.Show("密码不能为空");
            }
            else if (determinepwd == "")
            {
                MessageBox.Show("确定密码不能为空");
            }
            else
            {
                if (pwd == determinepwd)
                {
                    string Sql = "server=.;database=Blogs;uid=sa;pwd=123456";
                    con = new SqlConnection(Sql);
                    string cmd = string.Format("insert into Users values('{0}','{1}')", uid, pwd);
                    SqlCommand com = new SqlCommand(cmd, con);
                    con.Open();
                    if (com.ExecuteNonQuery() != 0)
                        MessageBox.Show("注册成功！");
                    else
                        MessageBox.Show("注册不成功！");
                    con.Close();
                }
                else
                {
                    MessageBox.Show("确定密码不相同");
                }
            }
            

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
